package com.frogs.ucenter.v1.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.UserFeedbackAddRequest;
import com.frogs.ucenter.v1.service.UserFeedbackService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Controller(ApiConstants.VERSION+"UserFeedbackController")
@RequestMapping("/"+ApiConstants.VERSION)
public class UserFeedbackController {
    private static final Log log = LogFactory.getLog(UserFeedbackController.class);
	
    private static final String FEEDBACK_ADD = "/user/feedback/add";

    @Autowired
    @Qualifier(ApiConstants.VERSION+"userFeedbackService")
    private UserFeedbackService userFeedbackService;

    @RequestMapping(FEEDBACK_ADD)
	public Response feedBackAdd(HttpServletRequest request) {
		Response response = null;
		try {
			UserFeedbackAddRequest userFeedbackAddRequest = new UserFeedbackAddRequest();
			userFeedbackAddRequest.parse(request);
			response = userFeedbackService.insert(userFeedbackAddRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}

}